package com.phkj.qdh.ui.adapter.usercenter

import android.content.Context
import android.view.ViewGroup
import android.widget.TextView
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.phkj.qdh.R
import com.phkj.qdh.bean.MyBaseInspectBean

class MyBaseInspectAdapter : BaseQuickAdapter<MyBaseInspectBean, QuickViewHolder>() {
    override fun onBindViewHolder(
        holder: QuickViewHolder, position: Int, item: MyBaseInspectBean?
    ) {
        holder.setText(R.id.tv_type_name, item?.keyPointTypeName)
        holder.setText(R.id.tv_state, item?.stateName)
        holder.setText(R.id.tv_date, item?.checkTime.toString())
        holder.setText(R.id.tv_remark, item?.remark?:"")

        val sb = StringBuilder()
        item?.detail?.forEach{
//            sb.append("${it.fieldName}：${it.fieldValue}\n")
            if (it.fieldKey=="name"){
                holder.setText(R.id.k, "${it.fieldName}：")
                holder.setText(R.id.v, it.fieldValue)
            }
        }
        if (sb.length>2) {
            holder.setText(R.id.tv_key_value, sb.substring(0,sb.length-2).toString())
        }
        val tvState  = holder.getView<TextView>(R.id.tv_state)
        tvState.text= when (item?.state) {
            1 -> {"待下发"}
            2 -> {"待处理"}
            3 -> {"已反馈"}
            4 -> {"已驳回"}
            5 -> {"已退回"}
            6 -> {"已完成"}
            else -> {"记录"}
        }
    }

    override fun onCreateViewHolder(
        context: Context, parent: ViewGroup, viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_my_notice_base, parent)
    }
}